package com.phonebook.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.oas.annotations.EnableOpenApi;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

import java.util.ArrayList;

/**
 * Knife4jConfig
 *
 * @author 高旭
 * @date 2021-09-08
 */
@Configuration
@EnableOpenApi
public class Knife4jConfig {

    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("电话簿")  // 配置api文档的分组
                .enable(true)  // 配置是否开启swagger
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.phonebook")) //配置扫描路径
                .build();
    }

    // api基本信息
    private ApiInfo apiInfo() {
        return new ApiInfo("dxiaodang's swagger",
                "测试swagger-ui",
                "v1.0",
                "http://mail.qq.com",
                new Contact("dangbo", "http://mail.qq.com", "145xxxxx@qq.com"),  //作者信息
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<VendorExtension>());
    }

}
